﻿<%@ page language="java" import="java.util.*" contentType="text/html; charset=UTF-8"%>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<%@ page import="nc.vo.sm.UserVO"%>
<%@ page import="nc.bs.ebvp.login.Constant"%>
<%@ page import="nc.bs.ebvp.sourcingcoll.Constants"%>
<%@ page import="nc.bs.ebvp.sourcingcoll.form.PriceDetailForm"%>
<%@ page import="nc.bs.ebvppub.ebvpservicefactory.LoadConfigProperty"%>

<%
	String basePath = request.getContextPath();
	List listTotalPrice = (List)request.getAttribute(Constants.ID_TOTAL_PRICE);
	List listDetailPrice = (List)request.getAttribute(Constants.ID_DETAIL_PRICE);
	String strQuoteIndex = request.getParameter("quote_index");
	if(strQuoteIndex == null){
		strQuoteIndex = "0";
	}
	String[] strCssClass = null;
	if(null != listTotalPrice && listTotalPrice.size() > 0){
		strCssClass = new String[listTotalPrice.size()];
		for(int i=0;i<strCssClass.length;i++){
			strCssClass[i] = "blue_label";
		}
		strCssClass[Integer.parseInt(strQuoteIndex)] = "white_label";
	}
	String strQuoteType = (String)request.getAttribute("quoteType");
	String strLunOrCi = "次";
	if("1".equals(strQuoteType)){
		strLunOrCi = "轮";
	}
	String strParaEc021 = (String)request.getSession().getAttribute(Constants.ID_EC021);
	UserVO userVo = (UserVO)request.getSession().getAttribute(Constant.USER_INFO);
	boolean isClientCa = false;
	//供应商客户端是否支持CA
	if("Y".equalsIgnoreCase(strParaEc021) || (null != userVo.getIsca() && userVo.getIsca().booleanValue())){
		isClientCa = true;
	}
	//CA厂商名称
	String strCaFactory = (String)request.getSession().getAttribute(LoadConfigProperty.EBVP_CA_FACTORY);
	String strIsConfirm = request.getParameter("isconfirm");
	if(strIsConfirm == null){
		strIsConfirm = (String)request.getAttribute("isconfirm");
	}
%>
<html xmlns="http://www.w3.org/1999/xhtml">
	<head>
		<script type="text/javascript" src="js/jquery.form.js"></script>
		<%if(isClientCa){%>
			<%if(Constants.CA_FACTORY_ITRUS.equals(strCaFactory)){%>
				<script type="text/javascript" src="js/itrusforNC.js"></script>
				<script type="text/javascript" src="js/pta.js"></script>
			<%} else if(Constants.CA_FACTORY_INFOSEC.equals(strCaFactory)){%>
				<script type="text/javascript" src="js/Infosec4NC.js"></script>
			<%} else if(Constants.CA_FACTORY_DEAN.equals(strCaFactory)){%>
				<script type="text/javascript" src="js/DatechJs.js"></script>
			<%} %>
		<%}%>
		<script type="text/javascript">
		$(document).ready(function() {
		var options = {
			beforeSubmit : showRequest, 
			success : showResponse
			};
			$('#priceform').ajaxForm(options);
		});
		</script>
	</head>
	<body class="fullbody">
		<form id="priceform" name="priceform" method="post" action="<%=basePath%>/sourcing/biddingprojlist/confirmprice">
		<input type="hidden" name="casn" value=""/>
		<input type="hidden" name="signature" value=""/>
		<input type="hidden" name="projPk" value="${projPk}"/>
		<input type="hidden" name="onlineQuotePk" value="${onlineQuotePk}"/>
		<input type="hidden" name="quoteType" value="${quoteType}"/>
		<div class="context">
			<div class="position">
				<div class="tposi">
					当前位置：
					<a href="<%=basePath%>/infopub/pubmain" class="linkstyle">首页</a>&nbsp;&gt;&gt;&nbsp;
					<a href="<%=basePath%>/sourcing/projlist" class="linkstyle">我的投标\谈判\询价</a>&nbsp;&gt;&gt;&nbsp;
					<a href="<%=basePath%>/sourcing/biddingprojlist" class="linkstyle">进行中的项目</a>&nbsp;&gt;&gt;&nbsp;
					<a href="<%=basePath%>/sourcing/biddingprojlist/projexec?pk_pur_project=" class="linkstyle">${project_name}</a>&nbsp;&gt;&gt;&nbsp;
					<a href="<%=basePath%>/sourcing/biddingprojlist" class="linkstyle">在线竞价室</a>&nbsp;&gt;&gt;&nbsp;
					<span class="curposition">报价历史</span>
				</div>
				<div class="help">
					<a href="javascript:void(null);" onclick="doHelp('<%=request.getContextPath()%>/help/html/JJBJJGQR.html');" class="linkstyle">帮助</a>
				</div>
			</div>
			<div class="margin8">
			</div>
			<div class="subpage_title">
				<div class="title_index">
					<img src="<%=basePath%>/images/common/dot03.gif" alt="" border="0" />&nbsp;&nbsp;竞价数据
				</div>
				<div class="rollback">
					<a href="<%=basePath%>/sourcing/biddingprojlist" class="linkstyle">&lt;&lt;&nbsp;返回进行中的项目</a>
				</div>
			</div>
			<div class="margin10">
			</div>
			<div class="price_history_label">
				<%
					if(null != listDetailPrice && listDetailPrice.size() > 0){
						for(int i=0;i<=listDetailPrice.size();i++){
				%>
				<div class="<%=strCssClass[i]%>" onclick="javascript:document.location='<%=basePath%>/sourcing/biddingprojlist/getoldquote?projPk=${projPk}&onlineQuotePk=${onlineQuotePk}&quoteType=${quoteType}&quote_index=<%=i%>&isconfirm=<%=strIsConfirm%>'">
					<p align="center">
						<%
							if(i == 0){
						%>
							报价历史
						<% 
							}else{
						%>
							第<%=i%><%=strLunOrCi%>报价
						<% 
							}
						%>
					</p>
				</div>
				<%
						}
					}else if(null != listTotalPrice && listTotalPrice.size() > 0){
				%>
				<div class="white_label" onclick="">
				<p align="center">
					报价历史
				</p>
				</div>
				<%
					}else{
				%>
					无报价
				<%
					}
				%>
			</div>
			<div class="margin50">
			</div>
			<%
				if("0".equals(strQuoteIndex)){
			%>
			<div class="price_history_info">
				<table cellpadding="0" cellspacing="0" class="tableCss">
					<% 
						if(null != listTotalPrice){
							for(int i=0;i<listTotalPrice.size();i++){
								List list = (List)listTotalPrice.get(i);
								if(i == 0){
					%>
						<tr class="titleTr">
								<%
									for(int j=0;j<list.size();j++){
								%>
								<th>
									<%=list.get(j).toString()%>
								</th>
								<% 
									}
								%>
						</tr>
					<% 
								}else{
					%>
						<tr class="contTr-old">
								<%
									for(int j=0;j<list.size();j++){
								%>
								<td>
									<%
										if(j == 0){
									%>
										<%=list.get(j).toString()%>
									<% 
										}else{
									%>
										<input name="total_amount" class="input-unEdit words-blue" type="text" value="<%=list.get(j).toString()%>" readonly />
									<% 
										}
									%>
								</td>
								<% 
									}
								%>
						</tr>
					<% 
								}
							}
						}
					%>
				</table>
			</div>
			<%
				}else{
			%>
			<div class="price_history_view">
				<table cellpadding="0" cellspacing="0" class="tableCss">
					<tr class="titleTr">
						<th width="35px">序号</th>
						<th width="267px">产品</th>
						<th width="106px">数量</th>
						<th width="173px">价格</th>
						<th width="219px">备注</th>
					</tr>
					<%
						List listDetail = (List)listDetailPrice.get(Integer.parseInt(strQuoteIndex)-1);
						for(int i=0;i<listDetail.size();i++){
							PriceDetailForm form = (PriceDetailForm)listDetail.get(i);
					%>
					<%if((i % 2) == 1){%>
						<tr align="left" class="contTr-old"  >
					<%}else{%>
						<tr align="left" class="contTr-even">
					<%}%>
						<td class="td3"><%=i+1%></td>
						<td class="td3">
						<span class="prodName">
						<%if(null !=form.getProd_name() && !"".equals(form.getProd_name().trim())){%>
							<%=form.getProd_name()%>
						<%}else{%>
							<%=form.getConfig_note()%>
						<%}%>
						</span><br/>
						<%if(null !=form.getProd_spec() && !"".equals(form.getProd_spec().trim())){%>规格：<%=form.getProd_spec()%><br/><%}%>
						<%if(null !=form.getProd_type() && !"".equals(form.getProd_type().trim())){%>型号：<%=form.getProd_type()%><br/><%}%>
						<%if(null !=form.getProducer() && !"".equals(form.getProducer().trim())){%>生产厂商：<%=form.getProducer()%><br/><%}%>
						<%if(null !=form.getAsistantproperty() && !"".equals(form.getAsistantproperty().trim())){%>描述：<%=form.getAsistantproperty()%><br/><%}%>
						</td>
						<td class="td3">
						<input type="hidden" name="amount_precision" value="<%=form.getAmount_precision()%>" />
						<input name="amount_display" class="input-unEdit words-blue" type="text" value="<%=form.getAmount()%>" readonly />
						<%=form.getProd_unit_name()%>
						</td>
						<td class="td3">
						含税单价：<input name="has_tax_price" type="text" class="input-unEdit words-blue" value="<%=form.getHas_tax_price()%>" readonly /><br/>
						折扣率：<input name="detail_discount" type="text" class="input-unEdit words-blue" value="<%=form.getDetail_discount()%>" readonly /><br/>
						税率：<input name="tax_rate" type="text" class="input-unEdit words-blue" value="<%=form.getTax_rate()%>" readonly /><br/>
						折后价：<input name="discount_net_price" class="input-unEdit words-blue" type="text" value="<%=form.getPriceAfterDiscount()%>" readonly /><br/>
						折后金额：<input name="discount_net_sum" class="input-unEdit words-blue" type="text" value="<%=form.getAmountAfterDiscount()%>" readonly /><br/>
						</td>
						<td class="td3"><%=form.getMemo()==null?"":form.getMemo()%></td>
					</tr>
					<%
						}
					%>
				</table>
			</div>
			<%
				}
			%>
			<div class="margin20">
            </div>
            <%if("1".equals(strIsConfirm)){%>
			<tr>
				<td colspan="4" align="right" valign="top">
					<table width="100%" border="0" cellspacing="0" cellpadding="0">
						<td width="113" height="40" align="center">
							&nbsp;
						</td>
						<td width="310" align="right">
							<input type="submit" class="buttonok" value="确认" />
						</td>
						<td width="187" align="center">
							&nbsp;
						</td>
					</table>
				</td>
			</tr>
			<%}%>
		</div>
		</form>
		<script language="javascript">
			// pre-submit callback 
			function showRequest(formData, jqForm, options) {
				//签名
				var bResult = true;
				<%if (isClientCa) {%>
					bResult = doVerify();
				<%}%>
				return bResult;
			}
		
			// post-submit callback 
			function showResponse(responseText, statusText, xhr, $form) {
				if(responseText == "success"){
					alert("确认成功！");
				}else{
					if(responseText.indexOf("error:") > -1){
						responseText = responseText.substring(6);
						alert(responseText);
					}
				}
				return;
			}
			
			function doVerify(){
				//证书SN
				var strSn = getSN("${USER_CODE}");
				if(strSn == null || strSn == ""){
					alert("请插入Key后再进行操作！");
					return false;
				}
				document.priceform.casn.value = strSn;
				//方案主键|发布类单据主键|供应商对应用户主键
				var strSignData = "${onlineQuotePk}" + "|" + "${USER_ID}";
				//签名
				document.priceform.signature.value = signmessage(strSignData,"${USER_CODE}");
				return true;
			}

			//设置显示值
			//合计金额
			var totalAmount = document.getElementsByName("total_amount");
			if(null != totalAmount){
				for(var i=0;i<totalAmount.length;i++){
					subReduNum(totalAmount[i],'${MONEY_PRECISION}');
				}
			}
			//数量
			var amountDisplay = document.getElementsByName("amount_display");
			var amountPrecision = document.getElementsByName("amount_precision");
			if(null != amountDisplay){
				for(var i=0;i<amountDisplay.length;i++){
					subReduNum(amountDisplay[i],amountPrecision[i].value);
				}
			}
			//含税单价
			var hasTaxPrice = document.getElementsByName("has_tax_price");
			if(null != hasTaxPrice){
				for(var i=0;i<hasTaxPrice.length;i++){
					subReduNum(hasTaxPrice[i],'${PRICE_PRECISION}');
				}
			}
			//税率
			var taxRate = document.getElementsByName("tax_rate");
			if(null != taxRate){
				for(var i=0;i<taxRate.length;i++){
					subReduNum(taxRate[i],2);
				}
			}
			//折扣率
			var detailDiscount = document.getElementsByName("detail_discount");
			if(null != detailDiscount){
				for(var i=0;i<detailDiscount.length;i++){
					subReduNum(detailDiscount[i],2);
				}
			}
			//折后价（含税净价或者无税竞价，统一取含税净价）
			var hasTaxNetPrices = document.getElementsByName("discount_net_price");
			if(null != hasTaxNetPrices){
				for(var i=0;i<hasTaxNetPrices.length;i++){
					subReduNum(hasTaxNetPrices[i],'${PRICE_PRECISION}');
				}
			}
			//折后金额（价税合计）
			var priceTaxSums = document.getElementsByName("discount_net_sum");
			if(null != priceTaxSums){
				for(var i=0;i<priceTaxSums.length;i++){
					subReduNum(priceTaxSums[i],'${MONEY_PRECISION}');
				}
			}
		</script>
	</body>
</html>
